<template>
  <div>
    <h1>{{ id ? `编辑` : `新建` }}热点推荐</h1>
    <el-form label-width="120px" @submit.native.prevent="save">
      <el-tabs value="hot_recommend" type="card">
        <el-tab-pane label="热点推荐" name="hot_recommend">
          <el-form-item label="热点标题">
            <el-input v-model="model.hot_recommend.title" />
          </el-form-item>
          <el-form-item label="热点内容">
            <el-input type="textarea" v-model="model.hot_recommend.content" />
          </el-form-item>
          <el-form-item label="热点时间">
            <el-input v-model="model.hot_recommend.time" />
          </el-form-item>
          <el-form-item label="图片链接" width="120">
            <el-input v-model="model.hot_recommend.img" />
          </el-form-item>
          <el-form-item label="热点描述一">
            <el-input type="textarea" v-model="model.hot_recommend.nr1" />
          </el-form-item>
          <el-form-item label="热点描述二">
            <el-input type="textarea" v-model="model.hot_recommend.nr2" />
          </el-form-item>
        </el-tab-pane>

        <el-tab-pane label="活动参与" name="action_join">
          <el-form-item label="活动标题">
            <el-input v-model="model.action_join.title" />
          </el-form-item>
          <el-form-item label="活动机构">
            <el-input v-model="model.action_join.jg" />
          </el-form-item>
          <el-form-item label="描述地点">
            <el-input v-model="model.action_join.address" />
          </el-form-item>
          <el-form-item label="活动时间">
            <el-input v-model="model.action_join.time" />
          </el-form-item>
          <el-form-item label="活动照片链接" width="120">
            <el-input v-model="model.action_join.img" />
          </el-form-item>
        </el-tab-pane>
      </el-tabs>

      <el-form-item style="margin-top: 1rem">
        <el-button type="primary" native-type="submit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    id: {},
  },
  data() {
    return {
      model: {
        action_join:{},
        hot_recommend: {},
      },
    };
  },
  methods: {
    async save() {
      let res;
      if (this.id) {
        res = await this.$http.put(`rest/Mix/${this.id}`, this.model);
      } else {
        res = await this.$http.post("rest/Mix", this.model);
      }
      this.$router.push("/mix/list");
      this.$message({
        type: "success",
        message: "保存成功",
      });
    },
    async fetch() {
      const res = await this.$http.get("rest/Mix/" + this.id);
      this.model = Object.assign({}, this.model, res.data);
      // 这样写也行
      // this.model = {...this.model,...res.data}
    },
    
  },
  created() { 
    this.id && this.fetch();
  },
};
</script>

<style scoped>
</style>